$(function() {
	$('#vue_vm_list div').hide();
});

var account = {
	id: '',
	staffId: '',
	account: '',
	password: '',
	status: '',
	createTime: '',
	updateTime: '',
	createId: '',
	updateId: '',
	remark: '',
};

var view = {
	data: account
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

function register() {
	view.data.staffId = $('input:radio[name="staffId"]:checked').val();
	view.data.account = $('#account').val();
	view.data.password = $('#password').val();
	password_cfm = $('#password_cfm').val();
	view.data.status = 0;
	
	if(isEmpty(view.data.staffId)) {
		alert('请选择职工');
		return;
	}
	if(isEmpty(view.data.account)) {
		alert('请输入账号');
		return;
	}
	if(isEmpty(view.data.password)) {
		alert('请输入密码');
		return;
	}
	if(isEmpty(password_cfm)) {
		alert('请再次输入密码');
		return;
	}
	if(view.data.password != password_cfm) {
		alert('两次密码输入不一致');
		return;
	}
	
	save_basic(path+'/account/register', {account:view.data}, function() {
		alert('账号开通成功');
	});
}

function findStaffInfo() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	var searchVal = $('#searchVal').val();
	
	openWaiting('正在查找');
	
	find_basic(path+'/staffInfo/find', searchVal, function(response) {
		$('#account').val(response.data[0].phoneNumber);
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
		
		closeWaiting();
	});
}

function login() {
	view.data.status = (view.data.status==''? 0: parseInt(view.data.status));
	
	login_basic(path+'/account/login', {account:view.data}, 
		function(response) {
			var loginedUser = {};
			loginedUser.staffId = response.data[0].staffInfoForm.staffId;
			loginedUser.staffName = response.data[0].staffInfoForm.name;
			loginedUser.personType = response.data[0].staffInfoForm.personType;
			loginedUser.personTypeName = response.data[0].staffInfoForm.personTypeName;
			loginedUser.subjectRoomId = response.data[0].staffInfoForm.subjectRoomId;
			loginedUser.subjectRoomName = response.data[0].staffInfoForm.subjectRoomName;
			loginedUser.departmentId = response.data[0].staffInfoForm.departmentId;
			loginedUser.departmentName = response.data[0].staffInfoForm.departmentName;
			loginedUser.dutyId = response.data[0].staffInfoForm.dutyId;
			loginedUser.dutyName = response.data[0].staffInfoForm.dutyName;
			loginedUser.typeOfDuty = response.data[0].staffInfoForm.typeOfDuty;
			
			setLoginedUser(loginedUser);
			window.location.href = 'zindex.html';
		},
		function(response) {
			slider.init();
			alert('登录失败');
		}
	);
}
